﻿<%@ WebHandler Language="C#" Class="GZHeatRecordInfoHandler" %>

using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;

public class GZHeatRecordInfoHandler : IHttpHandler, IRequiresSessionState
{

    CurrentUserInfo m_UserInfo;
    GZHeatRecordInfoBusiness m_HRI = new GZHeatRecordInfoBusiness();
    #region 页面初始化
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request["action"].ToString();
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            switch (action)
            {
                case "SaveHeatRecordInfo"://保存热处理记录
                    SaveHeatRecordInfo(context);
                    break;
                case "GetHeatRecordInfo"://查询热处理记录
                    GetHeatRecordInfo(context);
                    break;
                case "GZSTContainerRecord":
                    GZSTContainerRecord(context);
                    break;
                case"AddDrawingNo":
                    AddDrawingNo(context);
                    break;
                case "DeleteDrawingNo":
                    DeleteDrawingNo(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";

            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    #endregion

    private void SaveHeatRecordInfo(HttpContext context) 
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(context.Request["Base"].ToString());
        DataTable dt1 = JsonConvert.DeserializeObject<DataTable>(context.Request["Spec"].ToString());
        DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(context.Request["DrawingNos"].ToString());
        var CONTAINERID = context.Request["ContainerID"].ToString();
        var para=new Dictionary<string,string>();
        para.Add("CONTAINERID", CONTAINERID);
        para.Add("CREATEEMPLOYEEID", m_UserInfo.EmployeeID.ToString());
        uMESProcessResult result = new uMESProcessResult();
        result.Result=m_HRI.SaveHeatRecordInfo(dt, dt1, dt2, para);
        result.Message = result.Result ? "保存成功" : "保存失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    private void GetHeatRecordInfo(HttpContext context)
    {
        var CONTAINERID = context.Request["ContainerID"].ToString();
        uMESProcessResult result = new uMESProcessResult();
        result.DBDataSet = m_HRI.GetHeatRecordInfo(CONTAINERID);
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void GZSTContainerRecord(HttpContext context) 
    {
        var CONTAINERID = context.Request["ContainerID"].ToString();
        uMESProcessResult result = new uMESProcessResult();
        var para=new Dictionary<string,string>();
        para.Add("STDATE",DateTime.Now.ToString("yyyy-MM-dd"));
        para.Add("SAMPLENO","ST"+DateTime.Now.ToString("yyyyMMdd"));
        para.Add("CONTAINERID", CONTAINERID);
        para.Add("CREATEEMPLOYEE", m_UserInfo.FullName.ToString());
        result.ReturnData = para;
        result.DBDataSet = m_HRI.GZSTContainerRecord(para);
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void AddDrawingNo(HttpContext context) 
    {
        var CONTAINERID = context.Request["ContainerID"].ToString();
        var DrawingNo = context.Request["DrawingNo"].ToString();
        uMESProcessResult result = new uMESProcessResult();
        var para = new Dictionary<string, string>();
        para.Add("STDATE", DateTime.Now.ToString("yyyy-MM-dd"));
        para.Add("SAMPLENO", "ST" + DateTime.Now.ToString("yyyyMMdd"));
        para.Add("DrawingNo", DrawingNo);
        para.Add("CONTAINERID", CONTAINERID);
        para.Add("CREATEEMPLOYEEID", m_UserInfo.EmployeeID.ToString());
        para.Add("CREATEEMPLOYEE", m_UserInfo.FullName.ToString());
        result.Result = m_HRI.AddDrawingNo(para);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void DeleteDrawingNo(HttpContext context) 
    {
        var ids = context.Request["ids"].ToString();
        uMESProcessResult result = new uMESProcessResult();
        result.Result = m_HRI.DeleteDrawingNo(ids);
        result.Message = result.Result ? "删除成功" : "删除失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    
}